/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package canteen.sys.view;

import canteen.sys.SessionFactoryClass;
import canteen.sys.model.entity.LoginMaster;

/**
 *
 * @author TNT
 */
public class CanteenApp extends javax.swing.JFrame {

    /**
     * Creates new form CanteenApp
     */
    LoginMaster lm;

    public CanteenApp() {
        initComponents();
        lm = SessionFactoryClass.getInstance().getUser();
        try {
            if (lm.getlType().equals("admin")) {
                listenComponent();
            } else {
                this.dispose();
            }
        } catch (NullPointerException ex) {
            this.dispose();
        }
        //checkLogin();
    }

    public final void listenComponent() {
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        desktop = new javax.swing.JDesktopPane();
        menubar = new javax.swing.JMenuBar();
        menuMain = new javax.swing.JMenu();
        menuItemExit = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        menuItemFullScreen = new javax.swing.JMenuItem();
        menuMasterEntry = new javax.swing.JMenu();
        menuItemDepartment = new javax.swing.JMenuItem();
        menuItemSubDepartment = new javax.swing.JMenuItem();
        menuItemDesignation = new javax.swing.JMenuItem();
        menuItemItemType = new javax.swing.JMenuItem();
        menuItem = new javax.swing.JMenuItem();
        menuItemEmployee = new javax.swing.JMenuItem();
        menuSearch = new javax.swing.JMenu();
        menuBill = new javax.swing.JMenu();
        billEntryMenuItem = new javax.swing.JMenuItem();
        menuReport = new javax.swing.JMenu();
        menuItemDepartmentwise = new javax.swing.JMenuItem();
        menuItemEmployeewise = new javax.swing.JMenuItem();
        menuItemDatewise = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Canteen Management System");
        setMinimumSize(new java.awt.Dimension(800, 500));
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        desktop.addContainerListener(new java.awt.event.ContainerAdapter() {
            public void componentRemoved(java.awt.event.ContainerEvent evt) {
                desktopComponentRemoved(evt);
            }
        });

        menuMain.setText("Main");

        menuItemExit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK));
        menuItemExit.setText("Logout");
        menuItemExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemExitActionPerformed(evt);
            }
        });
        menuMain.add(menuItemExit);
        menuMain.add(jSeparator1);

        menuItemFullScreen.setText("Full Screen");
        menuItemFullScreen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemFullScreenActionPerformed(evt);
            }
        });
        menuMain.add(menuItemFullScreen);

        menubar.add(menuMain);

        menuMasterEntry.setText("Master Entry");

        menuItemDepartment.setText("Department");
        menuItemDepartment.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemDepartmentActionPerformed(evt);
            }
        });
        menuMasterEntry.add(menuItemDepartment);

        menuItemSubDepartment.setText("Sub Department");
        menuItemSubDepartment.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemSubDepartmentActionPerformed(evt);
            }
        });
        menuMasterEntry.add(menuItemSubDepartment);

        menuItemDesignation.setText("Designation");
        menuItemDesignation.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemDesignationActionPerformed(evt);
            }
        });
        menuMasterEntry.add(menuItemDesignation);

        menuItemItemType.setText("Item Type");
        menuItemItemType.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemItemTypeActionPerformed(evt);
            }
        });
        menuMasterEntry.add(menuItemItemType);

        menuItem.setText("Item");
        menuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemActionPerformed(evt);
            }
        });
        menuMasterEntry.add(menuItem);

        menuItemEmployee.setText("Employee");
        menuItemEmployee.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemEmployeeActionPerformed(evt);
            }
        });
        menuMasterEntry.add(menuItemEmployee);

        menubar.add(menuMasterEntry);

        menuSearch.setText("Search");
        menubar.add(menuSearch);

        menuBill.setText("Bill");
        menuBill.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuBillActionPerformed(evt);
            }
        });

        billEntryMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.CTRL_MASK));
        billEntryMenuItem.setText("Bill Entry");
        billEntryMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                billEntryMenuItemActionPerformed(evt);
            }
        });
        menuBill.add(billEntryMenuItem);

        menubar.add(menuBill);

        menuReport.setText("Report");

        menuItemDepartmentwise.setText("Departmentwise Expence");
        menuReport.add(menuItemDepartmentwise);

        menuItemEmployeewise.setText("Employeewise Expence");
        menuItemEmployeewise.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemEmployeewiseActionPerformed(evt);
            }
        });
        menuReport.add(menuItemEmployeewise);

        menuItemDatewise.setText("Datewise");
        menuReport.add(menuItemDatewise);

        menubar.add(menuReport);

        setJMenuBar(menubar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktop, javax.swing.GroupLayout.DEFAULT_SIZE, 800, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktop, javax.swing.GroupLayout.DEFAULT_SIZE, 479, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void menuItemDepartmentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemDepartmentActionPerformed
        // TODO add your handling code here:
        DepartmentEntry departmentEntry = new DepartmentEntry();
        desktop.add(departmentEntry);
        departmentEntry.setVisible(true);
    }//GEN-LAST:event_menuItemDepartmentActionPerformed

    private void menuItemEmployeewiseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemEmployeewiseActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_menuItemEmployeewiseActionPerformed

    private void menuItemExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemExitActionPerformed
        // TODO add your handling code here:
        SessionFactoryClass.getInstance().setUser(null);
        this.dispose();
    }//GEN-LAST:event_menuItemExitActionPerformed

    private void menuItemFullScreenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemFullScreenActionPerformed
        // TODO add your handling code here:
//        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
//        this.setLocation(0, 0);
//        this.setSize(dim);
    }//GEN-LAST:event_menuItemFullScreenActionPerformed

    private void menuBillActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuBillActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_menuBillActionPerformed

    private void billEntryMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_billEntryMenuItemActionPerformed
        // TODO add your handling code here:
//        BillEntry billEntry = new BillEntry();
//        desktop.add(billEntry);
//        billEntry.setVisible(true);
        OrderCheck orderCheck = new OrderCheck(lm);
        desktop.add(orderCheck);
        orderCheck.setVisible(true);

    }//GEN-LAST:event_billEntryMenuItemActionPerformed

    private void menuItemSubDepartmentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemSubDepartmentActionPerformed
        // TODO add your handling code here:
        SubDepartmentEntry subDepartment = new SubDepartmentEntry();
        desktop.add(subDepartment);
        subDepartment.setVisible(true);
    }//GEN-LAST:event_menuItemSubDepartmentActionPerformed

    private void menuItemDesignationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemDesignationActionPerformed
        // TODO add your handling code here:
        DesignatoinEntry designationEntry = new DesignatoinEntry();
        desktop.add(designationEntry);
        designationEntry.setVisible(true);
    }//GEN-LAST:event_menuItemDesignationActionPerformed

    private void menuItemItemTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemItemTypeActionPerformed
        // TODO add your handling code here:
        ItemTypeEntry itemTypeEntry = new ItemTypeEntry();
        desktop.add(itemTypeEntry);
        itemTypeEntry.setVisible(true);
    }//GEN-LAST:event_menuItemItemTypeActionPerformed

    private void menuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemActionPerformed
        // TODO add your handling code here:
        ItemEntry itemEntry = new ItemEntry();
        desktop.add(itemEntry);
        itemEntry.setVisible(true);
    }//GEN-LAST:event_menuItemActionPerformed

    private void menuItemEmployeeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemEmployeeActionPerformed
        // TODO add your handling code here:
        EmployeeEntry employeeEntry = new EmployeeEntry();
        desktop.add(employeeEntry);
        employeeEntry.setVisible(true);
    }//GEN-LAST:event_menuItemEmployeeActionPerformed

    private void desktopComponentRemoved(java.awt.event.ContainerEvent evt) {//GEN-FIRST:event_desktopComponentRemoved
        // TODO add your handling code here:
//        JOptionPane.showMessageDialog(this, "hey i show you!");
    }//GEN-LAST:event_desktopComponentRemoved

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        // TODO add your handling code here:
        SessionFactoryClass.getInstance().setUser(null);
    }//GEN-LAST:event_formWindowClosing
    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        /* Set the Nimbus look and feel */
//        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
//        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
//         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
//         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(CanteenApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(CanteenApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(CanteenApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(CanteenApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
//        //</editor-fold>
//
//        /* Create and display the form */
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new CanteenApp().setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem billEntryMenuItem;
    private javax.swing.JDesktopPane desktop;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JMenu menuBill;
    private javax.swing.JMenuItem menuItem;
    private javax.swing.JMenuItem menuItemDatewise;
    private javax.swing.JMenuItem menuItemDepartment;
    private javax.swing.JMenuItem menuItemDepartmentwise;
    private javax.swing.JMenuItem menuItemDesignation;
    private javax.swing.JMenuItem menuItemEmployee;
    private javax.swing.JMenuItem menuItemEmployeewise;
    private javax.swing.JMenuItem menuItemExit;
    private javax.swing.JMenuItem menuItemFullScreen;
    private javax.swing.JMenuItem menuItemItemType;
    private javax.swing.JMenuItem menuItemSubDepartment;
    private javax.swing.JMenu menuMain;
    private javax.swing.JMenu menuMasterEntry;
    private javax.swing.JMenu menuReport;
    private javax.swing.JMenu menuSearch;
    private javax.swing.JMenuBar menubar;
    // End of variables declaration//GEN-END:variables
//    private void checkLogin() {
//        LoginMaster user = SessionFactoryClass.getInstance().getUser();
//        Login login = new Login();
//        if (user == null) {
//            menubar.setVisible(false);
//            desktop.add(login);
//            login.setVisible(true);
//        } else {
//            menubar.setEnabled(true);
//            login.dispose();
//        }
//    }
}
